const path = require("path");
const json5 = require("json5");

module.exports = {
  entry: "./src/index.js",
  mode: "development",
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "dist"),
    // 4. 自动清理dist
    clean: true,
  },
  module: {
    rules: [
        // 1. 支持css解析
      {
        // 正则匹配
        test: /\.css$/i,
        // loader从后到前执行
        use: ["style-loader", "css-loader"],
      },
      // 2. 支持parse5解析
      {
        test: /\.json5$/i,
        type: "json",
        parser: {
          parse: json5.parse,
        },
      }
    ],
  },
  devServer: {
    static: "./dist",
    open:true,
    port: 3000
  },
  optimization: {
    splitChunks: {
      chunks: 'all',
    }
  }
};
